<html>
<body>

<p>
Provide a valid mySQL query in the box below and hit "Submit" for results: <br/>
</p>

<form method = "GET">
<textarea name = "que" cols = "60" rows = "8"></textarea>
<input type = "submit" value = "Submit">
</form>

<?php
if($_GET["que"]){
	$query = $_GET["que"];
	$db_connection = mysql_connect("localhost", "cs143", "");
	mysql_select_db("CS143", $db_connection);
	$sanitized_name = mysql_real_escape_string($name, $db_connection);
	$query_to_issue = sprintf($query, $sanitized_name);

	$result = mysql_query($query_to_issue, $db_connection);
	$test = mysql_fetch_row($result);

	echo "<table border='1'>";
	echo"<tr>";
	$size1 = count($test);
	$cnt1 = 0;
	while($cnt1 < $size1){
		$attribute = mysql_field_name($result, $cnt1);
		$cnt1 = $cnt1 + 1;
		echo "<td> $attribute </td>";
	}
	mysql_data_seek($result, 0);
	echo "</tr>";
	
	while($row = mysql_fetch_row($result)) {
		$size = count($row);
		$cnt = 0;
		echo "<tr>";
		while($cnt < $size){
			$col = $row[$cnt];
			if($col == false)
				$col = "N/A";
			$cnt = $cnt + 1;
			echo "<td>$col</td>";
		}
		echo "</tr>";
	}
	echo "</table>";
	mysql_close($db_connection);	
}
?>

</body>
</html>
